package com.zuul.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

@Component
public class ErrorFilter extends ZuulFilter {

	@Override
	public String filterType() {
		/**
		 * 前面过滤器执行错误时调用，用来记录错误信息
		 */
		return FilterConstants.ERROR_TYPE;
	}


	@Override
	public int filterOrder() {
		return 0;
	}
	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public Object run() throws ZuulException {
		System.out.println("----------------错误过滤器执行---------------------");
		RequestContext currentContext = RequestContext.getCurrentContext();
		Object isSucess = currentContext.get("isSucess");
		String message = currentContext.getThrowable().getMessage();
		return null;
	}


}
